/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 * @flow
 */

import React, { Component } from 'react';
import {
  Platform,
  StyleSheet,
  Text,
  View,
  ActivityIndicator,
  TouchableHighlight,
  Image
} from 'react-native';
import TabNavigator from 'react-native-tab-navigator';
import {Navigator} from 'react-native-deprecated-custom-components';
import icon from './icon';
import Home from './src/home/home';
import MoiveHot from './src/moive/moive_hot';

const instructions = Platform.select({
  ios: 'Press Cmd+R to reload,\n' +
    'Cmd+D or shake for dev menu',
  android: 'Double tap R on your keyboard to reload,\n' +
    'Shake or press menu button for dev menu',
});

export default class App extends Component {

  state={
    'selectedTab':'home' 
  }
  render() {
    const TabItem = TabNavigator.Item
    return (
      <View style={styles.container}>
        <TabNavigator style={styles.tab}>
          <TabItem
          title="home"
          selected={this.state.selectedTab === 'home'}
          renderIcon={()=><Image source={require('./src/icons/compass.png')} style={styles.icon} />}
          renderSelectedIcon={()=><Image source={require('./src/icons/compass-active.png')} style={styles.icon} />}
          onPress={()=>{
            this.setState({'selectedTab':'home'})
          }}
          badgeText="1"
          >
            <Home />
          </TabItem>
          <TabItem
          title="game"
          selected={this.state.selectedTab === 'game'}
          renderIcon={()=><Image source={require('./src/icons/check-circle.png')} style={styles.icon} />}
          renderSelectedIcon={()=><Image source={require('./src/icons/check-circle-active.png')} style={styles.icon} />}
          onPress={()=>{
            this.setState({'selectedTab':'game'})
          }}>
            <Game />
          </TabItem>
          <TabItem
          title="moive"
          selected={this.state.selectedTab === 'moive'}
          renderIcon={()=><Image source={require('./src/icons/check-circle.png')} style={styles.icon} />}
          renderSelectedIcon={()=><Image source={require('./src/icons/check-circle-active.png')} style={styles.icon} />}
          onPress={()=>{
            this.setState({'selectedTab':'moive'})
          }}>
            <Navigator 
              style={{flex: 1}}        // 布局
              initialRoute={{
                title:'热门电影',
                component: MoiveHot
              }}
              renderScene={(route, navigator) => {    // 将板块生成具体的组件
                let Component = route.component;    // 获取路由内的板块
                return <Component {...route.params} navigator={navigator} />    // 根据板块生成具体组件
              }}
            />
            {/* <MoiveHot /> */}
          </TabItem>
          <TabItem
          title="user"
          selected={this.state.selectedTab === 'user'}
          renderIcon={()=><Image source={require('./src/icons/check-circle.png')} style={styles.icon} />}
          renderSelectedIcon={()=><Image source={require('./src/icons/check-circle-active.png')} style={styles.icon} />}
          onPress={()=>{
            this.setState({'selectedTab':'user'})
          }}>
            <User />
          </TabItem>
        </TabNavigator>
      </View>
    );
  }
}

function Game() {
  return (
    <View>
      <Text>i am Game</Text>
    </View>
  )
}

function User() {
  return (
    <View>
      <Text>i am User</Text>
    </View>
  )
}

const styles = StyleSheet.create({
  tab:{
    height:30
  },
  container: {
    flex: 1,
    justifyContent: 'flex-start',
    backgroundColor: '#F5FCFF',
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
  instructions: {
    textAlign: 'center',
    color: '#333333',
    marginBottom: 5,
  },
  icon:{
    width:20,
    height:20
  }
});
